# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=twolame
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.13
pkgrel=3
pkgdesc="An optimized MPEG Audio Layer 2 (MP2) encoder (mingw-w64)"
arch=('any')
license=('LGPL')
url="http://www.twolame.org/"
options=('staticlibs' 'strip')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libsndfile")
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-mingw32-does-not-need-handholding.all.patch
        0002-no-undefined-on.mingw.patch
        0003-binary-stdin.all.patch
        0004-no-need-for-dllexport.mingw.patch
        0005-silent.mingw.patch)
sha256sums=('98f332f48951f47f23f70fd0379463aff7d7fb26f07e1e24e42ddef22cc6112a'
            '9151f5a78e188fde7ff14e92b5d04d2a198d0916d7ad3dfcd556d0ebadc0b24b'
            'a4234841bdc2e4432e1a7187317df5ef06c92693ba6019830c8540f3635905d3'
            'de8f7e115aef6a0f365fce39d048136f183d6c046221722193f7ffb471e85e1e'
            'c6b4d26198f3ab98dcf1db6fe384c9159d6a2e6b3b7bb18a4d58ef046c64b282'
            '47cb6d31a4c1f236bfb0c57d2a600c0d225babe5c36b8a1e4313db0fe62e8213')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-mingw32-does-not-need-handholding.all.patch
  patch -p1 -i ${srcdir}/0002-no-undefined-on.mingw.patch
  patch -p1 -i ${srcdir}/0003-binary-stdin.all.patch
  patch -p1 -i ${srcdir}/0004-no-need-for-dllexport.mingw.patch
  patch -p1 -i ${srcdir}/0005-silent.mingw.patch

  WANT_AUTOMAKE=latest autoreconf -fi
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
